package com.dd.controller;

import com.dd.pojo.Coach;
import com.dd.pojo.Course;
import com.dd.pojo.User;
import com.dd.pojo.Vip;
import com.dd.service.CoachService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/coach")
public class CoachController {
    @Autowired
    CoachService coachService;


    @RequestMapping("/selectcoach")
    public String selectcoach() throws JsonProcessingException {

        ObjectMapper mapper = new ObjectMapper();
        List<Coach> list = coachService.selectcoach();
        String str = mapper.writeValueAsString(list);
        String jso ="{\"code\":0,\"msg\":\"\",\"count\":" + 25 + ",\"data\":" + str + "}";
        return jso;
    }

    @RequestMapping("/addcoach")
    public String addcoach(Coach coach){
        coachService.addcoach(coach);
        return "1";
    }

    @RequestMapping("/updatecoach")
    public String updatecoach(Coach coach){
        coachService.updatecoach(coach);
        return "1";
    }

    @RequestMapping("/deletecoach")
    public String deletecoach(int id){
        coachService.deletecoach(id);
        return "1";
    }


    @RequestMapping("/selectname")
    public String selectname() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        List<String> s = coachService.selectname();
        String str = mapper.writeValueAsString(s);
        return str;
    }

    @RequestMapping("/selectbyjname")
    public String selectbykname(String jname) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        List<Coach> selectbyjname = coachService.selectbyjname(jname);
        String str = mapper.writeValueAsString(selectbyjname);
        String j ="{\"code\":0,\"msg\":\"\",\"count\":" + 25 + ",\"data\":" + str + "}";
        return j;
    }


}
